home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / MacHacksBug / Python 1.5.2c1 / Lib / test / test_operator.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2000-06-23  |  2.5 KB  |  112 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 1.5)
  3.  
  4. import operator
  5. import sys
  6.  
  7. def test(name, input, output, *args):
  8.     print 'testing:', name
  9.     f = getattr(operator, name)
  10.     params = (input,) + args
  11.     
  12.     try:
  13.         val = apply(f, params)
  14.     except:
  15.         val = sys.exc_type
  16.  
  17.     if val != output:
  18.         print '%s%s = %s: %s expected' % (f.__name__, params, `val`, `output`)
  19.     
  20.  
  21. test('abs', -1, 1)
  22. test('add', 3, 7, 4)
  23. test('and_', 15, 10, 10)
  24. test('concat', 'py', 'python', 'thon')
  25. test('countOf', [
  26.     1,
  27.     2,
  28.     1,
  29.     3,
  30.     1,
  31.     4], 1, 3)
  32. a = [
  33.     4,
  34.     3,
  35.     2,
  36.     1]
  37. test('delitem', a, None, 1)
  38. if a != [
  39.     4,
  40.     2,
  41.     1]:
  42.     print 'delitem() failed'
  43.  
  44. a = range(10)
  45. test('delslice', a, None, 2, 8)
  46. if a != [
  47.     0,
  48.     1,
  49.     8,
  50.     9]:
  51.     print 'delslice() failed'
  52.  
  53. a = range(10)
  54. test('div', 5, 2, 2)
  55. test('getitem', a, 2, 2)
  56. test('getslice', a, [
  57.     4,
  58.     5], 4, 6)
  59. test('indexOf', [
  60.     4,
  61.     3,
  62.     2,
  63.     1], 1, 3)
  64. test('inv', 4, -5)
  65. test('isCallable', 4, 0)
  66. test('isCallable', operator.isCallable, 1)
  67. test('isMappingType', operator.isMappingType, 0)
  68. test('isMappingType', operator.__dict__, 1)
  69. test('isNumberType', 8.3, 1)
  70. test('isNumberType', dir(), 0)
  71. test('isSequenceType', dir(), 1)
  72. test('isSequenceType', 'yeahbuddy', 1)
  73. test('isSequenceType', 3, 0)
  74. test('lshift', 5, 10, 1)
  75. test('mod', 5, 1, 2)
  76. test('mul', 5, 10, 2)
  77. test('neg', 5, -5)
  78. test('or_', 10, 15, 5)
  79. test('pos', -5, -5)
  80. a = range(3)
  81. test('repeat', a, a + a, 2)
  82. test('rshift', 5, 2, 1)
  83. test('sequenceIncludes', range(4), 1, 2)
  84. test('sequenceIncludes', range(4), 0, 5)
  85. test('setitem', a, None, 0, 2)
  86. if a != [
  87.     2,
  88.     1,
  89.     2]:
  90.     print 'setitem() failed'
  91.  
  92. a = range(4)
  93. test('setslice', a, None, 1, 3, [
  94.     2,
  95.     1])
  96. if a != [
  97.     0,
  98.     2,
  99.     1,
  100.     3]:
  101.     print 'setslice() failed:', a
  102.  
  103. test('sub', 5, 2, 3)
  104. test('truth', 5, 1)
  105. test('truth', [], 0)
  106. test('xor', 11, 7, 12)
  107. test('indexOf', [
  108.     4,
  109.     3,
  110.     2,
  111.     1], ValueError, 9)
  112.